package com.tianyu.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

/**********************************
 * @Author YSW
 * @Description
 * @Date 2024/5/23 - 22:30
 **********************************/

@Slf4j
@Service
public class GlobalTool {

    /**
     * 修改时间为东8区
     */
    public static String modifyTimeToE8(String date) {
        Date oldDate = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        try {
            oldDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        if (oldDate != null) {
            calendar.setTime(oldDate);
        }
        calendar.add(Calendar.HOUR_OF_DAY, +8);
        return simpleDateFormat.format(calendar.getTime());
    }

}
